const { DataTypes } = require('sequelize');
const sequelize = require('../../config/database');

const Activities = sequelize.define('activities', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    allowNull: false
  },
  club_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '所属社团ID',
    references: {
      model: 'clubs',
      key: 'id'
    }
  },
  title: {
    type: DataTypes.STRING(100),
    allowNull: false,
    comment: '活动标题'
  },
  type: {
    type: DataTypes.STRING(50),
    allowNull: true,
    comment: '活动类型（如：比赛、讲座、聚会等）'
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '活动描述'
  },
  location: {
    type: DataTypes.STRING(255),
    allowNull: true,
    comment: '活动地点'
  },
  start_time: {
    type: DataTypes.DATE,
    allowNull: false,
    comment: '活动开始时间'
  },
  end_time: {
    type: DataTypes.DATE,
    allowNull: false,
    comment: '活动结束时间'
  },
  signup_deadline: {
    type: DataTypes.DATE,
    allowNull: false,
    comment: '报名截止时间'
  },
  max_participants: {
    type: DataTypes.INTEGER,
    allowNull: true,
    comment: '活动最多可报名人数'
  },
  points: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: true,
    defaultValue: 0.00,
    comment: '参加该活动可获得的积分'
  },
  created_at: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW,
    allowNull: false
  }
}, {
  tableName: 'activities',
  timestamps: false, // 禁用默认的 createdAt 和 updatedAt
  charset: 'utf8mb4',
  collate: 'utf8mb4_general_ci',
  comment: '社团发布的活动'
});

// 定义与clubs表的关联关系
Activities.associate = (models) => {
  Activities.belongsTo(models.clubs, {
    foreignKey: 'club_id',
    onDelete: 'CASCADE',
    onUpdate: 'RESTRICT'
  });
};



module.exports = Activities;
